<template>
	<view v-if="pageShow">
		<view class="block">
			<view class="xiaobai ershiba">账户余额</view>
			<view class="xiaobai fonweight margin_top2" style="font-size: 60rpx;">{{userInfo.yjnb_money}}
				<text class="xiaobai titletext">元</text>
			</view>
		</view>
		<view class="mainpadding ffffff block2">
			<view class="titletext fonweight zhonghei">充值</view>
			<view class="input margin_top">
				<input class=" " placeholder="自定义充值个数" type="number" v-model="pay_price" />
			</view>
			<view class="titletext fonweight margin_top zhonghei">支付方式</view>
			<view class="flexbetween margin_top" @click="pay_type=10">
				<view class="flexleft">
					<u-icon name="weixin-circle-fill" color="#26db6f" size="28"></u-icon>
					<view class="titletext hei_text margin_left">微信</view>
				</view>
				<u-icon name="checkmark-circle-fill" v-if="pay_type==10" color="#c1282e" size="24"></u-icon>
				<u-icon name="checkmark-circle-fill" v-if="pay_type!=10" color="#999" size="24"></u-icon>
			</view>
			<view class="margin_top flexbetween" @click="pay_type=20">
				<view class="flexleft">
					<u-icon name="zhifubao-circle-fill" color="#55aaff" size="28"></u-icon>
					<view class="titletext hei_text margin_left">支付宝</view>
				</view>
				<u-icon name="checkmark-circle-fill" v-if="pay_type==20" color="#c1282e" size="24"></u-icon>
				<u-icon name="checkmark-circle-fill" v-if="pay_type!=20" color="#999" size="24"></u-icon>
			</view>
			<view class="margin_top flexbetween" @click="pay_type=30">
				<view class="flexleft">
					<u-icon name="integral-fill" color="#c1282e" size="28"></u-icon>
					<view class="titletext hei_text margin_left">对公打款</view>
				</view>
				<u-icon name="checkmark-circle-fill" v-if="pay_type==30" color="#c1282e" size="24"></u-icon>
				<u-icon name="checkmark-circle-fill" v-if="pay_type!=30" color="#999" size="24"></u-icon>
			</view>
			<template v-if="pay_type==30">
				<view class="titletext fonweight margin_top zhonghei">对公账户信息</view>
				<view class="xiaohei main_size margin_top">名称：{{dginfo.dg_username}}</view>
				<view class="xiaohei main_size margin_top">银行：{{dginfo.dg_openbank}}</view>
				<view class="xiaohei main_size margin_top">账号：{{dginfo.dg_account}}</view>
				<view class="flexbetween margin_top">
					<view class="titletext fonweight  zhonghei">上传打款凭证</view>
					<view class="" @click="uploadImg()" v-if="image!=''">
						<view class=" " style="width: 140rpx;height: 140rpx;position: relative;">
							<image :src="image_text" class=" radius" style="width: 100%;height: 100%;" mode=""></image>
						</view>
					</view>
					<view class="" @click="uploadImg()" v-if="image==''">
						<image src="@/static/tjtp.png" class="" style="width: 140rpx;height: 140rpx;" mode="">
						</image>
					</view>
				</view>

			</template>
		</view>
		<view class="gudingdb mainpadding flexbetween">
			<view class="czbtn flexcenter" @click="tzczj">充值记录</view>
			<view class="ljcz flexcenter" @click="chongzhi()">立即充值</view>
		</view>
	</view>
</template>
<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				userInfo: {},
				pageShow: false,
				pay_price: "",
				pay_type: 10,
				dginfo: {},
				image: "",
				image_text: "",
			}
		},
		onShow() {
			this.init()
			this.getConfiginfo()
		},
		methods: {
			getConfiginfo() {
				httpRequest.request('/api/index/getConfigInfo', 'GET', {}).then(res => {
					this.dginfo = res.data.dginfo
				})
			},
			init() {
				httpRequest.request('/api/user/yjnbData', 'GET', {}).then(res => {
					this.userInfo = res.data
					this.pageShow = true
				})
			},
			// 跳转充值记录
			tzczj() {
				uni.navigateTo({
					url: '/pages/tab4/chongzhijl'
				})
			},
			chongzhi() {
				if (this.pay_price == "") {
					httpRequest.toast("请输入充值金额")
					return false
				}
				if (this.pay_type == 30 && this.image == "") {
					httpRequest.toast("请上传打款凭证")
					return false
				}
				uni.showLoading({
					mask: true,
					title: "请稍后"
				})
				httpRequest.request('/api/Yjnbmoneycl/rechargeMoney', 'POST', {
					price: this.pay_price,
					pay_type: this.pay_type,
					dk_image: this.pay_type == 30 ? this.image : ""
				}).then(res => {
					uni.hideLoading()
					console.error(111)
					if (res.code == 1) {
						if (this.pay_type == 10) { //微信
							console.error(222)
							uni.requestPayment({
								provider: 'wxpay',
								orderInfo: res.data.appconfig, //后台返回的支付数据
								success: function(res) {
									uni.navigateBack(1)
								},
								fail: function(err) {
									console.log(err)
								}
							});
						} else if (this.pay_type == 20) { //支付宝
							uni.requestPayment({
								provider: 'alipay',
								orderInfo: res.data.appconfig, //后台返回的支付数据
								success: function(res) {
									uni.navigateBack(1)
								},
								fail: function(err) {
									console.log(err)
								}
							});
						} else {
							httpRequest.toast(res.msg)
							setTimeout(() => {
								uni.navigateBack(1)
							}, 1000)
						}
					} else {
						httpRequest.toast(res.msg)
					}

				})
			},
			uploadImg(value, upImgs, upImgs_text) { //上传图片
				let _this = this;
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(1, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(1, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			uploadImageService(url, upImg, upImgs_text) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
					this.image = res.url
					this.image_text = image_item
				}).catch(err => {});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.ljcz {
		width: 328rpx;
		height: 76rpx;
		font-size: 26rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 800;
		background-color: #c1282e;
		border: 2rpx solid #c1282e;
		border-radius: 6rpx;
		color: #FFFFFF;
	}

	.czbtn {
		width: 328rpx;
		height: 76rpx;
		font-size: 26rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 800;
		background-color: #fff;
		border: 2rpx solid #c1282e;
		border-radius: 6rpx;
		color: #c1282e;
	}

	.input {
		background: #F6F6F6;
		border-radius: 6rpx 6rpx 6rpx 6rpx;
		padding: 30rpx;
	}

	.block2 {
		border-radius: 16rpx 16rpx 0 0;
		position: relative;
		top: -20rpx;
	}

	.block {
		padding: 40rpx 30rpx 40rpx;
		background-color: #c1282e;
	}
</style>